package com.feng.leetcode;

import java.util.*;

/**
 * @author feng
 * @decrition 先将order中的字符串取出，剩余的放到字符串中，遍历将剩余的加到字符串末尾
 * @date 2022/11/1312:02
 */
public class L791 {
    public static String customSortString(String order, String s) {
        StringBuilder sb = new StringBuilder();
        Map<Character, Integer> map = new LinkedHashMap<>();
        for (int i = 0; i < s.length(); i++) {
            if (order.indexOf(String.valueOf(s.charAt(i))) != -1) {
                map.put(s.charAt(i), map.getOrDefault(s.charAt(i), 0) + 1);
            } else {
                sb.append(s.charAt(i));
            }
        }
        for (int i = 0; i < order.length(); i++) {
            Integer integer = map.get(order.charAt(i));
                if (integer != null) {
                    continue;
                }
            for (int j = 0; j < integer; j++) {
                sb.append(order.charAt(i));
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        customSortString("kqep", "pekeq");
    }
}
